using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Triton.Common
{
	public class TypeLoader<T> : List<T>
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class Class236
		{
			public static readonly Class236 Instance9 = new Class236();

			public static Func<object[]> Instance9__2_0;

			public static Func<Type, bool> Instance9__3_2;

			public static Func<Type, bool> Instance9__3_1;

			public static Func<Assembly, IEnumerable<Type>> Instance9__3_0;

			internal object[] method_0()
			{
				return null;
			}

			internal IEnumerable<Type> method_1(Assembly assembly_0)
			{
				return from type_0 in assembly_0.GetTypes()
					where !type_0.IsAbstract && (type_0.IsSubclassOf(typeof(T)) || type_0.GetInterfaces().Any((Type type_0) => type_0 == typeof(T)))
					select type_0;
			}

			internal bool method_2(Type type_0)
			{
				if (!type_0.IsAbstract)
				{
					if (!type_0.IsSubclassOf(typeof(T)))
					{
						return type_0.GetInterfaces().Any((Type type_0) => type_0 == typeof(T));
					}
					return true;
				}
				return false;
			}

			internal bool method_3(Type type_0)
			{
				return type_0 == typeof(T);
			}
		}

		[CompilerGenerated]
		private sealed class Class237
		{
			public Type type_0;

			internal bool method_0(T gparam_0)
			{
				string fullName = gparam_0.GetType().FullName;
				string fullName2 = type_0.FullName;
				return fullName == fullName2;
			}
		}

		private readonly Assembly assembly_0;

		private Func<object[]> func_0;

		public TypeLoader(Assembly asm = null, Func<object[]> constructorArguments = null)
		{
			assembly_0 = asm;
			if (constructorArguments == null)
			{
				func_0 = () => null;
			}
			else
			{
				func_0 = constructorArguments;
			}
			Reload();
		}

		private void method_0(params Assembly[] assembly_1)
		{
			foreach (Type type_ in assembly_1.SelectMany((Assembly assembly_0) => from type_0 in assembly_0.GetTypes()
				where !type_0.IsAbstract && (type_0.IsSubclassOf(typeof(T)) || type_0.GetInterfaces().Any((Type type_0) => type_0 == typeof(T)))
				select type_0))
			{
				if (!this.Any(delegate(T gparam_0)
				{
					string fullName = gparam_0.GetType().FullName;
					string fullName2 = type_.FullName;
					return fullName == fullName2;
				}))
				{
					Add((T)Activator.CreateInstance(type_, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, func_0(), CultureInfo.InvariantCulture));
				}
			}
		}

		public void Reload()
		{
			Clear();
			if (assembly_0 == null)
			{
				method_0(AppDomain.CurrentDomain.GetAssemblies());
				return;
			}
			method_0(assembly_0);
		}
	}
}
